﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using wpfForPrism.Views;

namespace wpfForPrism.ViewModels
{
	internal class MainWindowViewModel : BindableBase
    {
        public readonly IDialogService dialogService;

        private readonly IRegionManager regionManager;
        /// <summary>
        /// 导航记录
        /// </summary>
        private IRegionNavigationJournal journal; 
        public DelegateCommand<string> ShowContentCommand { get; set; }
        public DelegateCommand<string> ShowMessageCommand { get; set; }
        public DelegateCommand BackCommand { get; set; }
        public MainWindowViewModel(IRegionManager regionManager,IDialogService _dialogService)
        {
            ShowContentCommand = new DelegateCommand<string>(ShowContentFunc);
            BackCommand = new DelegateCommand(BackCommandFunc);
            ShowMessageCommand = new DelegateCommand<string>(ShowMessageCommandFunc);
            this.regionManager = regionManager;
            dialogService = _dialogService;
        }
        internal void ShowContentFunc(string viewValue) {
            NavigationParameters paras = new NavigationParameters();
            paras.Add("MsgA","大家好，我是A");
            regionManager.Regions["ContentRegion"].RequestNavigate(viewValue,p=> {
                journal = p.Context.NavigationService.Journal;
            }, paras);
            //ShowContent = viewValue switch
            //{
            //    "UCA" => new UCA(),
            //    "UCB" => new UCB(),
            //    "UCC" => new UCC(),
            //    _=>new UCA()
            //};
        }
        private void BackCommandFunc() { journal.GoBack(); }
        internal void ShowMessageCommandFunc(string viewValue)
        {
            DialogParameters paras = new DialogParameters();
            paras.Add("Title","title1");
            paras.Add("Id", "100");

            dialogService.ShowDialog(viewValue, paras, t => {
                var result= t;
            });
        }
        /// <summary>
        /// 顯示的内容
        /// </summary>
        private UserControl _ShowContent;

        public UserControl ShowContent
		{
			get { return _ShowContent; }
			set { _ShowContent = value; RaisePropertyChanged(); }
		}

    }
}
